<?php require_once('Connections/MWLReversiConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['AdminName'])) {
  $loginUsername=$_POST['AdminName'];
  $password=$_POST['AdminPassword'];
  $MM_fldUserAuthorization = "priv";
  $MM_redirectLoginSuccess = "UserTableAdmin.php";
  $MM_redirectLoginFailed = "adminPage.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_MWLReversiConn, $MWLReversiConn);
  	
  $LoginRS__query=sprintf("SELECT adminname, adminpass, priv FROM administrators WHERE adminname=%s AND adminpass=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $MWLReversiConn) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'priv');
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>MWLReversi</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<!--[if IE]>
<style type="text/css">
#sidebar #calendar {
	background-position: 0px 20px;
}
</style>
<![endif]-->
</head>
<body>
<div id="logo">
	<h1><a href="#">MWLReversi</a></h1>
	<h2></a>Gra Planszowa Online</h2>
</div>
<div id="menu">
	<ul>
		<li class="first"><a href="index.php" accesskey="1" title="">Strona Główna</a></li>
		<li><a href="userPage.php" accesskey="2" title="">Użytkownik</a></li>
		<li><a href="adminPage.php" accesskey="3" title="">Administrator</a></li>
		<li><a href="playGamePage.php" accesskey="4" title="">Zagraj</a></li>
	</ul>
</div>
<hr />
<div id="banner"><img src="images/img04.jpg" alt="" width="960" height="147" /></div>
<!-- start page -->
<div id="page">
	<!-- start content -->
	<div id="content">
			<div class="post">
            			<h2 class="title" align="center"><a href="#">Zaloguj Się Jako Administrator</a></h2>            
			<div class="entry">
<form ACTION="<?php echo $loginFormAction; ?>"  method="POST" name="LoginAdminForm">            
<table width="350" height="145" cellspacing="0" cellpadding="4" align="center">
  <tr>
    <th scope="row">nazwa użytkownika:</th>
    <td><input name="AdminName" type="text" size="20" maxlength="20" /></td>
  </tr>
  <tr>
    <th scope="row">hasło:</th>
    <td><input name="AdminPassword" type="password" size="20" maxlength="20" /></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><input name="LoginAdminButton" type="submit"  value="zaloguj się"/></td>
  </tr>
</table>
</form>
			</div>
		</div>

	</div>

	<!-- end content -->
	<!-- start sidebar -->
	<div id="sidebar">

	<!-- end sidebar -->
</div>
</div>
<!-- end page -->
<div id="footer">
	<p class="legal">Copyright (c) 2008 The Noobs. All rights reserved.</p>
</div>
</body>
</html>
